package br.edu.universo.si.projeto2.infojob.client.componentes.dialogboxes;

import br.edu.universo.si.projeto2.infojob.client.util.Util;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;

/**
 * COMPONENTE - Caixa de Dialogo de Informacao
 * @author Andrey A. de Oliveira
 * @since 07/09/2008
 */
public class InformationDialogBox extends DialogBox
{
	private final static String TITULO = "INFORMAÇÃO";
	private final static Image OK_ICON = new Image(Util.getImagensPath() + "information_icon.png");
	
	private FlexTable flexTable;
	private Button fecharBtn;
	
	public InformationDialogBox(String texto)
	{
		super(false, true);

		this.setText(InformationDialogBox.TITULO);
		this.setAnimationEnabled(true);
		
		fecharBtn = new Button("Fechar");
		
		flexTable = new FlexTable();
		flexTable.setCellSpacing(5);

		FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();

		// insere os componentes
		flexTable.setWidget(0, 0, InformationDialogBox.OK_ICON);
		flexTable.setWidget(0, 1, new HTML(texto));
		flexTable.setWidget(1, 0, fecharBtn);

		// coloca o botao de fechar no meio do rodape
		cellFormatter.setColSpan(1, 0, 2);
		cellFormatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);

		this.add(flexTable);
		
		// acao para fechar a caixa de dialogo
		fecharBtn.addClickListener(
			new ClickListener()
			{
				public void onClick(Widget sender)
				{
					InformationDialogBox.this.hide();
				}
			}
		);
	}
	
	@Override
	public void show()
	{
		int left = (Window.getClientWidth() - this.getOffsetWidth()) / 2;
		int top = (Window.getClientHeight() - this.getOffsetHeight()) / 2;

		this.setPopupPosition(left, top);
	//	this.center();
		super.show();
	}
}